package com.hospital.drug.drugzhou.controller;

import com.alibaba.fastjson.JSON;
import com.hospital.drug.drugzhou.entity.Drug;
import com.hospital.drug.drugzhou.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @description：
 * @author：zou
 * @date：2021/9/7 17:23
 * @versions：v1.0
 */
@Controller
@RequestMapping("/drug")
public class DrugController {

    @Autowired
    private DrugService drugService;

    //首页
    @RequestMapping("/index")
    public String index() {
        return "drug/drugzou/medicate";
    }

    //查询全部药品
    @RequestMapping("/drugs")
    @ResponseBody
    public String drugs() {
        List<Drug> drugs = drugService.drugs();
        return JSON.toJSONString(drugs);
    }

    //检查库存
    @RequestMapping("/drugList")
    @ResponseBody
    public String drugList() {
        List<Drug> drugList = drugService.drugList();
        return JSON.toJSONString(drugList);
    }

    //更新药品属性
    @RequestMapping("/updDrug")
    @ResponseBody
    public String updDrug(Integer id, String field, String value) {
        boolean b = drugService.updDrug(id, field, value);
        return JSON.toJSONString(b);
    }

    //药品分页
    @RequestMapping("/drugPage")
    @ResponseBody
    public Object drugPage(Integer page, Integer limit, String drugName, Integer drugType) {
        if (page == null) {
            page = 1;
        }
        if (limit == null) {
            limit = 5;
        }
        return drugService.selPage(drugName, drugType, limit, page);
    }

}
